<!--订单-->
<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="car-label">关键字:</div>
      <el-input v-model="listQuery.customerName" placeholder="姓名/手机号/身份证号" style="width: 180px;" class="filter-item" />
      <div class="car-label">提交时间:</div>
      <el-date-picker v-model="listQuery.createTime" placeholder="请选择提交时间" clearable style="width: 130px" class="filter-item" />
      <div class="car-label">贷款银行:</div>
      <el-select v-model="listQuery.loanBank" placeholder="请选择银行" clearable class="filter-item" style="width: 130px">
        <el-option v-for="item in loanBanks" :key="item.id" :label="item.bankName" :value="item.id" />
      </el-select>
      <div class="car-label">订单状态:</div>
      <el-select v-model="listQuery.flow" placeholder="请输入订单状态" clearable class="filter-item" style="width: 130px">
        <el-option v-for="item in statuss" :key="item.key" :label="item.name" :value="item.key" />
      </el-select>
      <el-button style="margin-left: 10px" class="filter-item" type="primary" icon="el-icon-search" @click="search">
        搜索
      </el-button>
      <el-button :loading="downloadLoading" class="filter-item right-btn" type="primary" @click="handleDownload">
        导出
      </el-button>
    </div>
    <ve-table
      style="width:100%"
      :columns="columns"
      :table-data="tableData"
      :border-x="true"
      row-key-field-name="id"
      :border-y="true"
      :row-style-option="rowStyleOption"
      :checkbox-option="checkboxOption"
    />
    <div class="table-pagination">
      <ve-pagination
        :total="totalCount"
        :page-index="pageIndex"
        :page-size="pageSize"
        @on-page-number-change="pageNumberChange"
        @on-page-size-change="pageSizeChange"
      />
    </div>
  </div>
</template>

<style>
  .table-pagination {
    margin-top: 20px;
    text-align: right;
  }
  .right-btn{
    float: right;
  }
</style>

<script>

export default {
  data() {
    return {
      downloadLoading: false,
      // page index
      pageIndex: 1,
      // page size
      pageSize: 10,
      loanBanks: [],
      tableData: [],
      statuss: [{ key: 'order', name: '待提交' },
        { key: 'credit', name: '待征信查询' },
        { key: 'apply', name: '待贷款申请' },
        { key: 'risk', name: '待风控审核' },
        { key: 'sign', name: '签约订单' },
        { key: 'loan', name: '放款订单' },
        { key: 'pledge', name: '抵押订单' },
        { key: 'filing', name: '归档订单' },
        { key: 'close', name: '结清订单' }],
      totalCount: 1,
      appId: '',
      listQuery: {},
      rowStyleOption: {
        stripe: true, // 斑马纹
        hoverHighlight: true, // hover高亮
        clickHighlight: true // 点击行高亮
      },
      checkboxOption: {
        // 行选择改变事件
        selectedRowChange: ({ row, isSelected, selectedRowKeys }) => {
          console.log(row, isSelected, selectedRowKeys)
        },
        // 全选改变事件
        selectedAllChange: ({ isSelected, selectedRowKeys }) => {
          console.log(isSelected, selectedRowKeys)
        }
      },
      columns: [
        {
          field: '',
          key: '1',
          // type=checkbox
          type: 'checkbox',
          title: '',
          width: 50,
          align: 'center'
        },
        {
          field: '',
          key: 'a',
          title: '序号',
          align: 'center',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            return (this.pageIndex - 1) * this.pageSize + rowIndex + 1
          },
          width: '100px'
        },
        { field: 'orderId', key: 'b', title: '订单编号', align: 'center', width: '150px',
          renderBodyCell: ({ row, column, rowIndex }, h) => {
            console.log(row)
            return (
              <span class={'id-column'} on-click={() => this.gotoDetail(row.id,row.status)}>{row.orderId}</span>)
          } },
        { field: 'status', key: 'c', title: '订单状态', align: 'center', width: '100px' },
        { field: 'customerName', key: 'd', title: '客户姓名', align: 'left', width: '100px' },
        { field: 'carBrand', key: 'e', title: '品牌', width: '100px' },
        { field: 'buyType', key: 'f', title: '车辆类别', width: '' },
        { field: 'loanAmount', key: 'g', title: '贷款金额', width: '100px' },
        { field: 'serviceGroup', key: 'h', title: '部门', width: '100px' },
        { field: 'serviceUser', key: 'i', title: '业务员', width: '100px' }
      ]
    }
  },
  computed: {
  },
  created() {
    this.appId = sessionStorage.getItem('appId')
    this.getBankList()
    this.initDatabase()
  },
  methods: {
    /**
     * 跳转详情
     * @date 2021/7/5
     * @param id
     */
    gotoDetail(id,status) {
      if(status == "待提交") {
        this.$router.push({ path: '/a-content/customer-reference/add-bussiness', query: { id: id, source: 'orderList' }})
      } else if(status == "待征信查询"){
        this.$router.push({ path: '/a-content/customer-reference/bank-refer-detail', query: { id: id, source: 'referenceList' }})

      } else if(status == "待贷款申请" || status == "待贷款信息确认") {
        this.$router.push({ path: '/a-content/loan/reference-detail-main', query: { id: id, source: 'loanList' }})
      } else if(status == "待风控审核") {
        this.$router.push({ path: '/a-content/risk-control/risk-control-detail', query: { id: id, source: 'riskList' }})
      } else if(status == "待收件") {
        this.$router.push({ path: '/a-content/risk-control/risk-control-detail', query: { id: id, source: 'riskList' }})
      }

     },
    /**
     * 导出
     * @date 2021/7/5
     */
    handleDownload() {},
    search() {
      this.pageIndex = 1
      this.initDatabase()
    },
    // page number change
    pageNumberChange(pageIndex) {
      this.pageIndex = pageIndex
      this.initDatabase()
    },

    // page size change
    pageSizeChange(pageSize) {
      this.pageIndex = 1
      this.pageSize = pageSize
      this.initDatabase()
    },
    /**
       * 获取银行列表数据
       * @date 2021-05-18
       */
    async getBankList() {
      const param = { appId: await sessionStorage.getItem('appId') }
      const data = await this.$http.post('/auth/bankSetup/listAll/', param)
      if (data.code === 200) {
        this.loanBanks = data.data
      }
    },
    // Simulation table data
    async initDatabase() {
      this.tableData = []
      this.listQuery.appid = this.appId
      const data = await this.$http.post('/flow/orders/list/' + this.pageIndex + '/' + this.pageSize, this.listQuery)
      console.log(data)
      if (data.code === 200) {
        data.data.records.map((item, index) => {
          // return item.rowKey = index
        })
        this.tableData = data.data.records
        this.totalCount = data.data.total
      }
    }
  }
}
</script>
